class Solution {
public:
    string compressString(string S) {
        if(S.size() <= 2) return S;
        string s;
        int fast = 0,slow = 0;
        while(fast < S.size()){
            if(S[fast] != S[slow]){
                s.push_back(S[slow]);
                s.append(to_string(fast - slow));
                slow = fast;
            }
            fast++;
        }
        s.push_back(S[slow]);
        s.append(to_string(fast - slow));
        if(s.size() >= S.size()) return S;
        return s;
    }
};
